include('shared.lua')

function MsgDrugFactory(msg)
	local refinery = msg:ReadShort()
	local booze = msg:ReadShort()
	local drugs = msg:ReadShort()
	local rands = msg:ReadShort()
	local sdefense = msg:ReadShort()
	local soffense = msg:ReadShort()
	local sweapmod = msg:ReadShort()
	local mode = msg:ReadShort()
	
	local rmode = "Money"
	if mode==1 then rmode="S. Offense"
	elseif mode==2 then rmode="S. Defense"
	elseif mode==3 then rmode="S. Weapon Mod"
	end

	local DFrame1 = vgui.Create('DFrame')
	DFrame1:SetSize(169, 240)
	DFrame1:Center()
	DFrame1:SetTitle('Drug Refinery')
	DFrame1:SetSizable(true)
	DFrame1:SetDeleteOnClose(false)
	DFrame1:MakePopup()

	local Drugs = vgui.Create('DLabel')
	Drugs:SetParent(DFrame1)
	Drugs:SetPos(9, 45)
	Drugs:SetText('Drugs:')
	Drugs:SizeToContents()

	local RDrugs = vgui.Create('DLabel')
	RDrugs:SetParent(DFrame1)
	RDrugs:SetPos(9, 60)
	RDrugs:SetText('Random Drugs:')
	RDrugs:SizeToContents()

	local SDrugs = vgui.Create('DLabel')
	SDrugs:SetParent(DFrame1)
	SDrugs:SetPos(9, 75)
	SDrugs:SetText('Superdrugs:')
	SDrugs:SizeToContents()

	local Booze = vgui.Create('DLabel')
	Booze:SetParent(DFrame1)
	Booze:SetPos(9, 30)
	Booze:SetText('Booze:')
	Booze:SizeToContents()

	local BoozeCount = vgui.Create('DLabel')
	BoozeCount:SetParent(DFrame1)
	BoozeCount:SetPos(49, 30)
	BoozeCount:SetText(drugs ..'/3')
	BoozeCount:SizeToContents()

	local DrugCount = vgui.Create('DLabel')
	DrugCount:SetParent(DFrame1)
	DrugCount:SetPos(49, 45)
	DrugCount:SetText(booze ..'/5')
	DrugCount:SizeToContents()

	local RandomCount = vgui.Create('DLabel')
	RandomCount:SetParent(DFrame1)
	RandomCount:SetPos(89, 60)
	RandomCount:SetText(rands ..'/10')
	RandomCount:SizeToContents()

	local RDrugCount = vgui.Create('DLabel')
	RDrugCount:SetParent(DFrame1)
	RDrugCount:SetPos(74, 75)
	RDrugCount:SetText(soffense .. '/3, ' .. sdefense .. '/3, ' .. sweapmod ..'/3')
	RDrugCount:SizeToContents()
	
	local Mode = vgui.Create('DLabel')
	Mode:SetPos(9, 90)
	Mode:SetText('Mode: '.. rmode)
	Mode:SetParent(DFrame1)
	Mode:SizeToContents()
	

	if(soffense>=3 && sdefense>=3 && sweapmod>=3) then
		local Eject = vgui.Create('DButton')
		Eject:SetParent(DFrame1)
		Eject:SetSize(52, 20)
		Eject:SetPos(106, 110)
		Eject:SetText('Eject')
		Eject.DoClick = function() LocalPlayer():ConCommand("setrefinerymode " .. refinery .. " eject\n") DFrame1:Remove() end

		local CreateUber = vgui.Create('DButton')
		CreateUber:SetParent(DFrame1)
		CreateUber:SetSize(91, 20)
		CreateUber:SetPos(9, 110)
		CreateUber:SetText('Create UberDrug')
		CreateUber.DoClick = function() LocalPlayer():ConCommand("setrefinerymode " .. refinery .. " uber\n") DFrame1:Remove() end
	else	
		local Eject = vgui.Create('DButton')
		Eject:SetParent(DFrame1)
		Eject:SetSize(150, 20)
		Eject:SetPos(9, 110)
		Eject:SetText('Eject SuperDrugs')	
		Eject.DoClick = function() LocalPlayer():ConCommand("setrefinerymode " .. refinery .. " eject\n") DFrame1:Remove() end
	end
	
	
		
	local Money = vgui.Create('DButton')
	Money:SetParent(DFrame1)
	Money:SetSize(150, 20)
	Money:SetPos(9, 135)
	Money:SetText('Refine to Money')
	Money.DoClick = function() LocalPlayer():ConCommand("setrefinerymode " .. refinery .. " money\n") DFrame1:Remove() end

	local Offense = vgui.Create('DButton')
	Offense:SetParent(DFrame1)
	Offense:SetSize(150, 20)
	Offense:SetPos(9, 160)
	Offense:SetText('Refine to Offense')
	Offense.DoClick = function() LocalPlayer():ConCommand("setrefinerymode " .. refinery .. " offense\n") DFrame1:Remove() end

	local Defense = vgui.Create('DButton')
	Defense:SetParent(DFrame1)
	Defense:SetSize(150, 20)
	Defense:SetPos(9, 185)
	Defense:SetText('Refine to Defense')
	Defense.DoClick = function() LocalPlayer():ConCommand("setrefinerymode " .. refinery .. " defense\n") DFrame1:Remove() end

	local WeaponMod = vgui.Create('DButton')
	WeaponMod:SetParent(DFrame1)
	WeaponMod:SetSize(150, 20)
	WeaponMod:SetPos(9, 210)
	WeaponMod:SetText('Refine to Weapon Mod')
	WeaponMod.DoClick = function() LocalPlayer():ConCommand("setrefinerymode " .. refinery .. " weapmod\n") DFrame1:Remove() end
end
usermessage.Hook("drugfactorygui", MsgDrugFactory)